"""
运行所有爬虫的脚本，有些不行，我改了
"""
import sys
import os

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from ..src.weather.weather_spider import WeatherForecast
from ..src.utils.database import DatabaseManager
import logging


def setup_logging():
    """设置日志"""
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    )


def run_weather_crawler():
    """运行天气爬虫"""
    print("=== 运行天气爬虫 ===")
    wf = WeatherForecast()
    cities = ["北京", "上海", "广州", "深圳"]
    wf.process(cities)
    print("天气爬虫完成\n")


def run_job_crawler():
    """运行招聘信息爬虫"""
    print("=== 运行招聘信息爬虫 ===")
    # 这里添加招聘爬虫代码
    print("招聘信息爬虫完成\n")


def main():
    """主函数"""
    setup_logging()

    print("开始运行所有爬虫...")

    # 初始化数据库
    db = DatabaseManager()
    db.create_tables()

    # 运行各个爬虫
    run_weather_crawler()
    run_job_crawler()

    print("所有爬虫运行完成！")


if __name__ == "__main__":
    main()